<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>添加薪酬单信息</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../../static/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../../static/css/admin.css" media="all">
  <style>
       .st{
           width: 270px!important;
       }
       .layui-form-label{
           width: 120px!important;
       }
  </style>
</head>
<body>

  <div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin" style="padding: 20px 0 0 0;">
    <div class="layui-inline layui-form-item">
      <label class="layui-form-label">部门名称</label>
      <div class="layui-input-inline">
        <select id="selectField" name="dept_father" lay-filter="fieldSelect" lay-search>
          <option value="">请选择部门</option>
        </select>
      </div>
    </div>
    <div class="layui-form-item layui-hide">
      <input type="button" lay-submit lay-filter="LAY-user-front-submit" id="LAY-user-front-submit" value="确认">
    </div>
  </div>

  <script src="../../../static/layui/layui.js"></script>

  <script>
    layui.config({
      base: '../../../static/layui/layuiadmin/' //静态资源所在路径
    }).extend({
      index: 'lib/index' //主入口模块
    }).use(['index', 'layer', 'form','layedit','laydate'], function(){
      var $ = layui.$
              ,form = layui.form
              ,layer = layui.layer
              ,laydate = layui.laydate
              ,layedit = layui.layedit;

      // 初始化表单
      form.render();

      // 使用Ajax请求获取字段列表数据
      $.ajax({
        url: '/pay/provide/department',
        type: 'GET',
        dataType: 'json',
        success: function (res) {
          if (res.code === 0) {
            var selectField = $('#selectField');

            // 清空下拉框中的选项
            selectField.empty();

            // 添加每个字段作为一个选项
            for (var i = 0; i < res.data.length; i++) {
              var option = $('<option></option>');
              var fieldValue = Object.values(res.data[i])[0];
              option.val(fieldValue);
              option.text(fieldValue);
              selectField.append(option);
            }

            // 重新渲染表单
            form.render('select');
          } else {
            layer.msg(res.msg, { icon: 2 });
          }
        },
        error: function (xhr, textStatus, errorThrown) {
          layer.msg('请求出错', { icon: 2 });
        }
      });


    })
  </script>
</body>
</html>